package com.li.server.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.li.client.entities.Publisher;
import com.li.server.jdbc.JDBCExecutor;
import com.li.server.jdbc.JDBCUtil;

public class PubliserDaoImpl implements PubliserDao {

	@Override
	public List<Publisher> getAllPublisher() {
		return new JDBCUtil().executeSQL(new JDBCExecutor<List<Publisher>>() {

			@Override
			public List<Publisher> execute(Connection conn) throws Exception {
				PreparedStatement ps = conn.prepareStatement("select PK_PUBLISHER_ID, NAME, ADDRESS, ZIP_CODE from PUBLISHER");
				ResultSet rs = ps.executeQuery();
				
				List<Publisher> pList = new ArrayList<Publisher>();
				
				while(rs.next()) {
					Publisher p = new Publisher();
					p.setPkPublisherId(rs.getInt("PK_PUBLISHER_ID"));
					p.setName(rs.getString("NAME"));
					p.setAddress(rs.getString("ADDRESS"));
					p.setZipCode(rs.getString("ZIP_CODE"));
					
					pList.add(p);
				}
				return pList;
			}
		});
	}

}
